<?php

namespace App\Models;

use Illuminate\Support\Collection;

class FrontForum extends Model
{
    protected $table = 'yf_front_forum';
    protected $primaryKey = 'forum_id';
    public $timestamps = false;
    protected $guarded = ['forum_id'];
    protected $casts = ['forum_content' => 'array'];

    /**
     * 补充版块活动数据
     *
     * @param string $type
     * @param array $ids
     * @param int $size
     * @return Collection
     */
    public static function addOpenForumContent(string $type, array $ids, int $size) : Collection
    {
        $map = [
            'groupbuy' => ['class' => GroupbuyBase::class, 'method' => 'getOpenForumGroupbuy'],
            'discount' => ['class' => DiscountGoods::class, 'method' => 'getOpenForumDiscount'],
            'redpacket' => ['class' => RedpacketTemplate::class, 'method' => 'getOpenForumRedpacket'],
            'voucher' => ['class' => VoucherTemp::class, 'method' => 'getOpenForumVoucher'],
            'pintuan' => ['class' => Pintuan::class, 'method' => 'getOpenPintuan']
        ];

        if (!array_key_exists($type, $map)) return collect([]);

        $class = $map[$type]['class'];
        $method = $map[$type]['method'];

        return $class::$method($ids, $size);
    }
}
